package com.zhuss.timer;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.zhuss.core.db.dao.ext.RepairSetDao;
import com.zhuss.core.db.entity.RepairSet;
import com.zhuss.enums.ConfigTypeEnum;
import com.zhuss.enums.RepairEnum;


//报修定时任务
@Component
@Configuration      
@EnableScheduling
public class RepairAutoPingJiaTask {
	
	@Autowired
	private RepairSetDao repairSetDao;
	
	//报修超过5天自动评价
    @Scheduled(cron = "10 18 10 * * ?")
    private void configureTasks() {
        // System.err.println("报修超时自动评价: " + LocalDateTime.now());
        Integer days = 5;	//默认自动好评时间5天
        Integer setDays = repairSetDao.getRepairPingJiaMaxDays(ConfigTypeEnum.评价时间阀值.value());
        if(null!=setDays){
        	days = setDays;
        }
        List<Integer> repairList = repairSetDao.getPingJiaDaysOutData(days);
        for(Integer repair_id : repairList){
        	pingJia(repair_id);
        } 
    }
    
    
    //报修数据评价
    public void pingJia(Integer repair_id){
    	//反馈表添加记录数据
        RepairSet repairSet= new RepairSet();
        repairSet.setRepair_id(repair_id);
        repairSet.setDeal_user_id(0);//param.getConcurrentUserId()
        repairSet.setContent("默认好评！");
    	repairSetDao.insertRepairPingJia(repairSet);
    	
    	//更新主表流程状态
    	RepairSet repairData = new  RepairSet();
    	repairData.setRepair_id(repair_id);
    	repairData.setStep(RepairEnum.维修评价完成.getStep());
    	repairData.setAudit(RepairEnum.维修评价完成.getAudit());
    	repairSetDao.updateRepairStatus(repairData);
    }
	
}
